<template>
	<view class="Page">
		<view class="title">查询结果</view>
		<view class="noData" v-show="type!='尚八目系统'&&type!='ERP_B系统'&&list==''">当前无查询数据</view>
		<view class="data_item" v-show="type=='尚八目系统'">
			<view class="card-left">
				<view><text class="gray">所在系统：</text>{{type}}</view>
				<view><text class="gray">物料名称：</text>{{list.spare_manage__name}}</view>
				<view><text class="gray">物料编码：</text>{{list.spare_manage__code}} {{' '}}<text class="gray">初始数量：</text>{{list.init_num}}</view>
				<view style="font-weight:600 ;">库存数量({{list.spare_manage__unit__name}})：<text style="color: red;">{{list.num}} </text></view> 
				<view><text class="gray">库存属性：</text>{{list.now_spare_status__name}}{{' '}}<text class="gray">型号：</text>{{list.spare_manage__model}}</view>
				<view><text class="gray">规格：</text> {{list.spare_manage__specs}}{{' '}}<text class="gray">流水号：</text>{{list.no}}</view>
				<view><text class="gray">材质：</text>{{list.spare_manage__material}}</view>
				<view><text class="gray">库存位置：</text>{{list.store_place__flag}}</view>
				<view><text class="gray">仓库名称：</text>{{list.store_place__storage__name}}</view>
				<view><text class="gray">供应商：</text>{{list.spare_batch__company__name}}</view>
				<view><text class="gray">供货日期：</text>{{list.spare_batch__date}}</view>
				
			</view>
		</view>
		<view class="data_item" v-show="type=='ERP_B系统'">
			<view class="card-left">
				<view><text class="gray">所在系统：</text>{{type}}</view>
				<view><text class="gray">物料名称：</text>{{list.spare_manage__name}}</view>
				<view><text class="gray">物料编码：</text>{{list.spare_manage__code}} {{' '}}<text class="gray">采购量：</text>{{list.init_num}}</view>
				<view style="font-weight:600 ;">库存数量({{list.spare_manage__unit__name}})：<text style="color: red;">{{list.num}} </text></view> 
				<view><text class="gray">库存属性：</text>{{list.now_spare_status__name}}{{' '}}</view>
				<view><text class="gray">型号：</text>{{list.spare_manage__model}}{{' '}}<text class="gray">规格：</text> {{list.spare_manage__specs}}</view>
				<view><text class="gray">材质：</text>{{list.spare_manage__material}}</view>
				<view><text class="gray">库存位置：</text>{{list.store_place__flag}}</view>
				<view><text class="gray">供应商：</text>{{list.company__name}}</view>
				<view><text class="gray">供货日期：</text>{{list.date}} </view>
				<view><text class="gray">库存金额：</text>{{list.amount}}</view>
				<view><text class="gray">登记人ID：</text>{{list.do_user_id}} {{' '}} <text class="gray">登记人：</text>{{list.do_user}}</view>
				<view v-for="(value,key,index) in list.data"><text class="gray">{{key}}：</text>{{value}}</view>
			</view>
		</view>
		<view class="title" v-show="type=='尚八目系统'">流水记录</view>
		<view class="noData" v-show="type=='尚八目系统'&&record_list.length==0">当前无流水记录</view>
		<view class="data_item" v-show="type=='尚八目系统'&&record_list.length>0" v-for="(item ,i) in record_list" :key="i">
			<view class="card-left">
				<view><text class="gray">库存状态：</text>{{item.spare_status__name}}</view>
				<view><text class="gray">记录类型：</text>{{item.record_type__name}}</view>
				<view><text class="gray">业务量：</text>{{item.num}} {{' '}} <text class="gray">库位：</text>{{item.store_place__flag}}</view>
				<view><text class="gray">操作人员：</text>{{item.do_user}}</view>
				<view><text class="gray">操作时间：</text>{{item.create_time}}</view>
				<view><text class="gray">备注：</text>{{item.bz}}</view>
			</view>	
		</view>
<!-- 		<uni-popup ref="ma_err" type="message">
			<uni-popup-message type="error" message="扫的码不是本系统的码" :duration="2000"></uni-popup-message>
		</uni-popup>
		<uni-popup ref="location" type="message">
			<uni-popup-message type="error" message="扫的码是位置码" :duration="2000"></uni-popup-message>
		</uni-popup>
		<uni-popup ref="idbucunzai" type="message">
			<uni-popup-message type="error" message="扫的码id不存在" :duration="2000"></uni-popup-message>
		</uni-popup> -->
		<view class="kongbai">
			
		</view>


	</view>
	<view class="buttonBox">
		<button size="default" type="default"  @click="scan1" class="scanButton">扫码</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				type:'',
				code:1234,
				// 二维码查询出的码
				qr_code:"",
				list:'',
				org_id:34,
				record_list:[],
			}
		},
		onLoad() {
			this.scan1();
		},
		methods: {
			scan1(){
				this.type='';
				this.list='';
				this.record_list=[];
				let that=this;
				uni.scanCode({
					scanType: ['qrCode'],
					success: function (res) {
						console.log(res.result)
						let strArray=res.result.split(',')
						console.log(strArray)
						if(strArray[0][5]=='d'){
							console.log('本系统')
							that.qr_code=strArray[0].slice(12);
							that.org_id=strArray[2].slice(7);
							// // 发起网络请求,查询信息
							// dd.httpRequest({
							//   url: 'http://113.15.231.21:180/storage_manage2/ding_app/query_spare_device_list',
							//   method: 'POST',
							//    headers: {
							// 		sessionid:that.$root.sessionID
							// 	},
							//   data: {
							// 	org_id:that.org_id, 
							// 	ids:that.qr_code, 
								
							//   },
							//   dataType: 'json',
							//   success: function(res){
							// 	  console.log(res)
							// 	if(res.data.result&&res.data.result.list&&res.data.result.list.length>0){
							// 		console.log("id存在");
							// 		that.list=res.data.result.list[0];
							// 		console.log('length'+that.list.length)
							// 		that.type="尚八目系统";
							// 		// console.log(that.list);
									
							// 		// 查询领用记录
							// 		dd.httpRequest({
							// 		  url: 'http://113.15.231.21:180/storage_manage2/ding_app/query_spare_record_list',
							// 		  method: 'POST',
							// 		  headers: {
							// 		  		sessionid:that.$root.sessionID
							// 		  	},
							// 		  data: {
							// 			org_id:34,
							// 			spare_device_id:res.data.result.list[0].id,
							// 		  },
							// 		  dataType: 'json',
							// 		  success: function(res1){
							// 			  console.log('流水记录')
							// 			  console.log(res1)
							// 			if(res1.data.result&&res1.data.result.list&&res1.data.result.list.length>0){
							// 				console.log("有流水记录");
							// 				that.record_list=res1.data.result.list;
							// 				// that.list=res.data.result.list[0];
							// 				// that.type="尚八目系统";
							// 				// console.log(that.list);
							// 			}
							// 			else{
							// 				console.log("无流水记录");
							// 				// that.$refs.idbucunzai.open('center')
							// 			}
							// 		},
							// 		  fail: function(res1) {
							// 			console.log("fail")
							// 			},
							// 		  complete: function(res1) {
							// 			console.log("com")
							// 			}
							// 		});
							// 	}
							// 	else{
							// 		console.log("id不存在");
							// 		that.$refs.idbucunzai.open('center')
							// 	}
							// },
							//   fail: function(res) {
							// 	console.log("fail")
							// 	},
							//   complete: function(res) {
							// 	console.log("com")
							// 	}
							// });
							
							that.$root.http('http://113.15.231.21:180/storage_manage2/ding_app/query_spare_device_list',
								{
									org_id:that.org_id, 
									ids:that.qr_code, 
								}, 
								{
								  	sessionid:that.$root.sessionID
								})
								.then((res) => {
									let fun=function(){
										if(res.data.result&&res.data.result.list&&res.data.result.list.length>0){
											console.log("id存在");
											that.list=res.data.result.list[0];
											console.log('length'+that.list.length)
											that.type="尚八目系统";
											// console.log(that.list);
											
											// 
											that.$root.http('http://113.15.231.21:180/storage_manage2/ding_app/query_spare_record_list',
												{
													org_id:34,
													spare_device_id:res.data.result.list[0].id,
												}, 
												{
												  	sessionid:that.$root.sessionID
												})
												.then((res1) => {
													let fun1=function(){
														console.log('流水记录')
														console.log(res1)
														if(res1.data.result&&res1.data.result.list&&res1.data.result.list.length>0){
															console.log("有流水记录");
															that.record_list=res1.data.result.list;

														}
														else{
															console.log("无流水记录");
														}
													}
													that.$root.judge(res,fun1);
											})
											
										}
										else{
											console.log("id不存在");
											// that.$refs.idbucunzai.open('center')
											that.$root.message('fail','扫的码id不存在')
										}
									}
									that.$root.judge(res,fun);
							})
							console.log('id'+id)

						}
						else if(strArray[0][5]=='_'){
							console.log("ERP_B");
							that.qr_code=strArray[0].slice(13);
							that.code=strArray[1].slice(5);
							console.log(that.qr_code);
							console.log(that.code);
							// console.log(that.qr_code)
							// 发起网络请求
							// dd.httpRequest({
							//   url: 'http://113.15.231.21:180/storage_manage2/ding_app/query_spare_batch_list',
							//   method: 'POST',
							//   headers: {
							//   	sessionid:that.$root.sessionID
							//   },
							//   data: {
							// 	org_id:34,
							// 	ids:[that.qr_code], 
							//   },
							//   dataType: 'json',
							//   success: function(res){
							// 	  console.log(res)
							// 	if(res.data.result&&res.data.result.list&&res.data.result.list.length>0){
							// 		console.log("id存在");
							// 		that.list=res.data.result.list[0];
							// 		that.type="ERP_B系统";
							// 		console.log(that.list);
							// 	}
							// 	else{
							// 		console.log("id不存在");
							// 		that.$refs.idbucunzai.open('center')
							// 	}
							// },
							//   fail: function(res) {
							// 	console.log("fail")
							// 	},
							//   complete: function(res) {
							// 	console.log("com")
							// 	}
							// });
							
							that.$root.http('http://113.15.231.21:180/storage_manage2/ding_app/query_spare_batch_list',
								{
									org_id:34,
									ids:[that.qr_code], 
								}, 
								{
								  	sessionid:that.$root.sessionID
								})
								.then((res) => {
									let fun=function(){
										console.log(res)
										if(res.data.result&&res.data.result.list&&res.data.result.list.length>0){
											console.log("id存在");
											that.list=res.data.result.list[0];
											that.type="ERP_B系统";
											console.log(that.list);
										}
										else{
											console.log("id不存在");
											// that.$refs.idbucunzai.open('center')
											that.$root.message('fail','扫的码id不存在')
										}
									}
									that.$root.judge(res,fun);
								})
						}
						else if(strArray[0][5]=='g'){
							console.log("位置");
							// that.$refs.location.open('center')
							that.$root.message('fail','扫的码是位置码')
						}
						else{
							console.log("扫的码不正确");
							// that.$refs.ma_err.open('center')
							that.$root.message('fail','扫的码不是本系统的码')
						}

					}
				});	
				
			},
		}
	}
</script>

<style scoped>
	.Page{
		width: 100%;
		font-size: 14px;
 		background-color: #F6F6F6;
		display: flex;
		flex-direction: column;
		/* align-items: center; */
		padding-left: 10px;
		/* padding-right: 10px; */
		
	}
	.title{
		font-size: 16px;
		margin-top: 10px;
		font-weight: 600;
		border-left: 2px solid dodgerblue;
		padding-left: 8px ;
	}
	.noData{
		margin-top: 15px;
	}
	

	.data_item{
		margin-top: 12px;
		width: 90%;
		/* margin-left:15px; */
		background-color: white;
		border-radius: 5px;
		font-size: 14px;
		padding-left: 10px;
		padding-bottom: 5px;
		
	}
	.card-left view{
		margin-top: 5px;
	}
	.gray{
		color: #93A1A1;
	}
	.num-icon{
		width: 20px;
		height: 20px;
	}
	.dialog_center{
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-items: center;
	}
	.is_show_box{
		width: 100%;
	}
	.kongbai{
		width: 100%;
		height: 60px;
	}
	.buttonBox{
		width: 100%;
		position: fixed;
		bottom: 0%;
	}
	.buttonBox button{
		width: 100%;
	}
	.scanButton{
		background-color: #42B983;
		/* background-color: #41A863; */
		color: white;
		border: 1px solid #42B983;
	}
</style>

 